package com.xps.charmingshop.date.net;

import android.content.SharedPreferences;
import android.support.annotation.Nullable;
import android.util.Log;


import com.jude.utils.JUtils;
import com.xps.charmingshop.App;
import com.xps.charmingshop.utils.SharedPreferencesUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;


public class LoggingInterceptor implements Interceptor {

    @Override
    public Response intercept(@Nullable Chain chain) throws IOException {
        Request request = chain.request();
        Request.Builder builder = request.newBuilder();
        SharedPreferences sp = JUtils.getSharedPreference();
        String access_token = sp.getString("access_token", "");
        builder.url(request.url().toString() + "?access-token=" + access_token);

        Response resp = chain.proceed(builder.build());
        if (resp.code() == 403) {
            Log.i("Logging", "退出");
            App.getInstance().exitApp();
        }
        return chain.proceed(builder.build());
    }
}
